package com.dgut.smart_house.mapper;

import com.dgut.smart_house.domain.Device;
import com.dgut.smart_house.dto.DeviceNodeDto;
import com.dgut.smart_house.dto.UserDeviceDto;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface DeviceMapper {


    public List<UserDeviceDto> findAllDevices(@Param("userId") Integer userId);


    public DeviceNodeDto findDeviceByDevId(Integer devId);

    @Delete("delete from user_device where dev_id=#{devId}")
    public Integer deleteDevice(Integer devId);

    @Update("update user_device set dev_desc=#{desc} where dev_id=#{devId}")
    public int updateDevice(@Param("devId") Integer devId,@Param("desc") String desc);

    @Insert("insert into user_device (node_id,from_user,dev_desc,type_id,command) values (#{nodeId},#{fromUser},#{devDesc},#{typeId},#{command})")
    public int createDevice(Device device);

    @Select("select from_user from user_device where dev_id=#{devId}")
    public Integer findUserByDevId(Integer devId);

    @Select("select status from user_device where dev_id=#{devId}")
    public int checkDeviceStatus(int devId);

    @Select("select * from user_device where dev_id=#{devId} ")
    public Device findDevice(int devId);

    @Select("select * from user_device where command=#{command}")
    public List<Device> findByCommand(String command);

    @Select("select * from user_device where type_id=#{typeId} and from_user=#{fromUser}")
    public Device findKeyDoor(@Param("typeId")int typeId,@Param("fromUser")int fromUser);

    @Select("select * from user_device where node_id=#{nodeId}")
    public List<Device> findByNodeId(int nodeId);
}
